/*
 * EnemyFactory.java
 *
 * Created on November 25, 2007, 2:19 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package hextd.sprite;

import hextd.util.Context;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author hylke
 */
public class EnemyFactory {
    public static enum Enemy {
        BlueBox         ("bb", new ESBlueBox()),
        FastForward     ("ff", new ESFastForward()),
        GreenPlus       ("gp", new ESGreenPlus()),
        HardGrey        ("hg", new ESHardGrey()),
        HealthyHelix    ("hh", new ESHealthyHelix()),
        PeachyPinata    ("pep", new ESPeachyPinata()),
        ProtectedPink   ("prp", new ESProtectedPink()),
        RedRaver        ("rr", new ESRedRaver()),
        SprintingSalmon("ss", new ESSprintingSalmon()),
        YellorRotor     ("yr", new ESYellowRotor());
        
        private final String name;
        private final EnemySprite instance;
        Enemy(String name, EnemySprite instance) {
            this.name = name;
            this.instance = instance;
        }
        public String getName() {
            return this.name;
        }
        public float getPreferredDelay() {
            return this.instance.getPreferredDelay();
        }
        public EnemySprite getCopy(Context context, int path, float delay, long health, int price, EnemySprite.Size s) {
            return instance.create(context, path, delay, health, price, s);
        }
    }
    private static Map<String, Enemy> table = new HashMap<String, Enemy>();
    static {
        for (Enemy enemy : Enemy.values()) {
            table.put(enemy.getName(), enemy);
        }
    }
    
    public static boolean isEnemy(String name) {
        return table.containsKey(getNamePart(name));
    }
    
    public static Enemy identifyEnemy(String name) {
        return table.get(getNamePart(name));
    }
    
    public static EnemySprite getEnemy(String name, Context context, int path, float delay, long health, int price) {
        return table.get(getNamePart(name)).getCopy(context, path, delay, health, price, getSize(name));
    }
    
    public static String getNamePart(String name) {
        switch (name.charAt(0)) {
            case 'L':
            case 'S':
            case 'N':
                return name.substring(1);
            default:
                return name;
        }
    }
        
    public static EnemySprite.Size getSize(String name) {
        switch (name.charAt(0)) {
            case 'L':
                return EnemySprite.Size.large;
            case 'S':
                return EnemySprite.Size.small;
            case 'N':
            default:
                return EnemySprite.Size.normal;
        }
    }
}
